//
//  ListViewController.m
//  ThePrivateKitchen
//
//  Created by lirui on 16/1/24.
//  Copyright © 2016年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "ListViewController.h"


@interface ListViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic ,retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *dataArr;
@end

@implementation ListViewController

- (void)dealloc
{
    [_tableView release];
    [_dataArr release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [ UIColor whiteColor];
    self.navigationItem.title = @"菜单";

    [self preparedata];
    [self creatView];
    [self loadMBProgress];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"left@3x"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(leftAction:)];
    
}
-(void)leftAction:(UIBarButtonItem *)left
{
    [self.navigationController popViewControllerAnimated:YES];
}

    


//获取数据
-(void)preparedata
{
    NSString *str = @"http://api.meishi.cc/v5/top.php?format=json?lat=38.88267593593907&lon=121.5393193060418&source=iphone&format=json&st=0&t=8&page=1";
    [LRAFNetwork postUrlString:str body:nil response:JSON bodyStyle:RequestJSON requestHeadFile:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSArray *arr = responseObject[@"d"];
        self.dataArr = [ TopicModel modelHanderWithArray:arr];
        [_tableView reloadData];
        [self.hud removeFromSuperview];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}
#pragma mark -创建tableview
-(void)creatView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH *375, HEIGHT *667) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = [UIColor whiteColor];
    [_tableView registerClass:[ListTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_tableView];
    [_tableView release];
    
    
}
#pragma mark -必须实现的方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   ListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    //传model
    cell.listModel = _dataArr[indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return HEIGHT *200;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ListdetailViewController *listdetail =[[ ListdetailViewController alloc] init];
    listdetail.model = _dataArr[indexPath.row];
    [self.navigationController pushViewController:listdetail animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
